#!/bin/sh
#
# this script is for autorestart daemon
# you can not remove this if you use autorestart 
#
#  (c) 2012 dangbinghoo, playpenguin.org
#

. /etc/init.d/rcfunctions


#
# autorestart daemon helper
# : $1- daemon bin
# : $2- params
# : $3- sleep times
# : $4- pid command for checking pid

if [ "$#" != "4" ];then
	rc_error "start_daemon function should have 4 params:
           cmd_filename params sleeptime checkpid_cmdname"
fi

while true;do
	proc_pid=`rc_check_proc_cmd "$4"`

	if [ -n "${proc_pid}" ];then
		# process running,do nothing.
		sleep 2
	else
		eval "$1 $2 & > /dev/null 2>&1"
	fi
done
